import axios from 'axios'
import Assert from '../../common/Assert.js'

export const CwInvoiceService = class CwInvoiceService{
    static cwInvoiceService =null;
    requestUrl = 'http://localhost/cwInvoices'

    static getInstance(){
        if(this.cwInvoiceService == null){
            this.cwInvoiceService = new CwInvoiceService()
        }
        return this.cwInvoiceService
    }

    //查询案件类型
    caseTypeList(){
        return axios.get("http://localhost/cwinout/caseType")
    }

    //查询所有数据
    list(params){
        return axios.get("http://localhost/cwinvoice",{
            params
        })
    }

    //查看我的发票
    cwinvoicegetById(caseLawId){
        return axios.get(`http://localhost/cwinvoice/${caseLawId}`)
    }

    /**
     * 检查的方法
     * @param cwInvoice
     */
    check(cwInvoice){
        if(!Assert.isNotNull(cwInvoice.cwInvoiceTitle,'请填写发票抬头')){
            return false
        }
        if(!Assert.isNotNull(cwInvoice.cwInvoiceMoney,'请填写开票金额')
            || !Assert.isLessZero(cwInvoice.cwInvoiceMoney,'请正确填写开票金额')){
            return false
        }
        if(!Assert.isNotNull(cwInvoice.cwTaxpayerIdentityNumber,'请填写纳税人识别号')){
            return false
        }
        if(!Assert.isNotNull(cwInvoice.cwInvoiceNumber,'请填写发票号')){
            return false
        }
        return true
    }

    /**
     * 保存发票信息
     * @param cwInvoice
     */
    save(cwInvoice){
        return axios.post(this.requestUrl,cwInvoice)
    }

    /**
     * 查询
     */
    kpList(params){
        return axios.get("http://localhost/cwinvoice/kpinvoice",{
            params
        })
    }

    /**
     * 删除发票记录
     */
    del(id){
        return axios.delete(`http://localhost/cwinvoice/${id}`)
    }
}